package test;

/**
 * @author 豆包LU
 * @date 2023/4/19 10:18
 */
public class ThreadExecutionOrderWithJoin {

    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            System.out.println("Thread 1 started");
            try {
                Thread.sleep(1000); // 线程1休眠1秒钟
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread 1 finished");
        });

        Thread thread2 = new Thread(() -> {
            System.out.println("Thread 2 started");
            try {
                Thread.sleep(1000); // 线程2休眠1秒钟
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println("Thread 2 finished");
        });

        thread1.start();
        try {
            thread1.join(); // 等待thread1执行完毕
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread2.start();
        try {
            thread2.join(); // 等待thread2执行完毕
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

